import React, { Component } from 'react';
import styles from './Service.less';
import { connect } from 'dva';
import getUrlParam from '@/utils/getUrlParam';

@connect(({ service }) => ({
  ServiceData: service.ServiceData,
}))
class Service extends Component {
  componentDidMount() {
    const { dispatch } = this.props;

    dispatch({
      type: 'service/getServiceData',
      payload: {
        api_type: 'service',
        page_num: 1,
        page_size: 10,
      },
    });
  }

  render() {
    let { ServiceData } = this.props;
    let renderService = () => {
      let res = [];
      if (!ServiceData) {
        return res;
      }
      if (ServiceData.data && ServiceData.data.data_list) {
        for (let i = 0; i < ServiceData.data.data_list.length; i++) {
          res.push(
            <div key={i} className={styles.goodsCard}>
              <div className={styles.reportImg}>
                <img
                  src={ServiceData.data.data_list[i].img_url}
                  alt={ServiceData.data.data_list[i].name}
                />
              </div>
              <div className={styles.reportTitle}>{ServiceData.data.data_list[i].name}</div>
              <div className={styles.reportDesc}>{ServiceData.data.data_list[i].desc}</div>
              <div className={styles.reportButtonWrap}>
                <a
                  href={ServiceData.data.data_list[i].pdf_url}
                  className={styles.reportLink}
                  target="_blank"
                  rel="noopener noreferrer"
                >
                  查看
                </a>
                <div className={styles.reportBuy}>购买</div>
              </div>
            </div>
          );
        }
      }
      return res;
    };
    return (
      <div>
        <div className={styles.mainBanner}>
          <p className={styles.mainBannerText}>
            为您提供财关、舆情课程培训、标准广告发布、官方微博运行等服务
          </p>
        </div>
        <div className={styles.listWrap}>{renderService()}</div>
      </div>
    );
  }
}

export default Service;
